package physics;

import java.awt.event.ActionEvent;

import viewControllers.ViewControllersFactory;

public class Weapon extends GameObject{
	protected int ticks = 0;
	protected int ticksToDisappear;
	protected boolean disappearing = false;
	private boolean canHit = true;
	protected boolean exploded = false;
	
	public void clockTicked(ActionEvent arg0) {
		if (!disappearing ||  (ticks < ticksToDisappear)){
			if (this.getMovementControler() != null){
				this.getMovementControler().play();
				setMoved(true);
			}
			if (disappearing){
				ticks++;
			}
		}else{
			this.exists = false;
		}
	}	

	public boolean canHit() {
		return canHit;
	}
	
	public void setCanHit(boolean canHit) {
		this.canHit = canHit;
	}

	public boolean isDisappearing(){
		return disappearing;
	}
	
	public void setDisappearing(boolean dis){
		this.disappearing = dis;
	}

	
	public void explode() {
		if (!exploded){
			disappearing = true;
			getMovementControler().restoreLastPosition();
			getMovementControler().setHasMomentum(false);
			this.setGraphicalObject(ViewControllersFactory.createExplosionViewController(this));
			exploded = true;
			radius *= 6; 
			ticks = 0;
		}
	}
	

}
